let path = require('path');
let root = process.cwd();
let { VueLoaderPlugin } = require('vue-loader');
// 拆分html
let HtmlWebpackPlugin = require('html-webpack-plugin');
// 拆分css
let MiniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = {
    // 开发环境
    mode: 'development',
    resolve: {
        alias: {
            'vue$': 'vue/dist/vue.js',
            '@': path.join(root, './src/'),
            '@c': path.join(root, './src/components/'),
            '@v': path.join(root, './src/views/'),
            '@t': path.join(root, './src/tools/')
        },
        extensions: ['.js', '.vue']
    },
    // 入口文件
    entry: './src/main.js',
    // 出口文件
    output: {
        path: path.join(root, '../server/static/admin'),
        filename: '[name].js',
        // 静态资源
        publicPath: '/static/admin/'
    },
    // 加载机
    module: {
        rules: [
            {
                test: /\.vue$/,
                use: [
                    'vue-loader'
                ]
            },
            {
                test: /\.css$/,
                use: [
                    'style-loader',
                    MiniCssExtractPlugin.loader,
                    'css-loader'
                ]
            },
            {
                test: /\.less$/,
                use: [
                    'style-loader',
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                    'less-loader'
                ]
            },
            {
                test: /\.scss$/,
                use: [
                    'style-loader',
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                    'sass-loader'
                ]
            },
            {
                test: /\.(woff|ttf)$/,
                use: [
                    'url-loader',
                ]
            },

        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
            template: './public/index.html',
            filename: path.join(root, '../server/views/admin.html'),
            hash: true
        }),
        new MiniCssExtractPlugin({
            filename: './style.css'
        })
    ],
    // 拆分库文件
    optimization: {
        splitChunks: {
            cacheGroups: {
                lib: {
                    name: 'lib',
                    chunks: 'initial',
                    test: /node_modules/
                }
            }
        }
    }
}